/**
 * 
 */
package ptvv.system;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.logging.Logger;

/**
 * @author dkz
 * 
 */
public class OutputPort {
	public BlockingQueue<String> queue = new LinkedBlockingQueue<String>(); // output
	public Thread destThread;
	public DefPortAutomaton destAutomata;
	public int receiverPortNum;
	public ThreadAndClass temp;

	public OutputPort(DefPortAutomaton dest, Thread destination) {
		this.destAutomata = dest;
		this.destThread = destination;
		// TODO Auto-generated constructor stub
	}

	public OutputPort(ThreadAndClass tac, int num) {
		this.temp = tac;
		this.destAutomata = tac.autoclass;
		this.destThread = tac.autothread;
		this.receiverPortNum = num;
		// TODO Auto-generated constructor stub
	}

	public OutputPort() {
	}

	public void setProperties(ThreadAndClass tac, int rec) {
		this.temp = tac;

		this.destAutomata = tac.autoclass;
		this.destThread = tac.autothread;
		this.receiverPortNum = rec;
	}

	public void sendInput() {
		int receiverportnum = this.receiverPortNum;
		String message = this.queue.poll();
		if (message != null)
			this.destAutomata.addInput(message, receiverportnum);

	}

	public void sendStart() {
		this.destAutomata.addEvent("Start");

	}

	public void interruptThread() {
		this.temp.autothread.interrupt();
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
